<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="app">
        <ul v-for="(item,index) in list">
            <li>
                <input type="checkbox" v-model="item.checked">
                {{item.name}}
            </li>
        </ul>
        {{list}}
        <p><input type="checkbox" v-model="checkAll" @change="changeALL">全选</p>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        let vm=new Vue({
            el:'.app',
            data:{
                checkAll:false,
                list:[
                    {
                        name:'小明',
                        checked:false,
                    },
                    {
                        name:'小花',
                        checked:false,
                    },
                    {
                        name:'小猪',
                        checked:false,
                    },
                    {
                        name:'小狗',
                        checked:false,
                    },
                ]
            },
            methods:{
                // 全选框的函数
                changeALL(){
                    this.list.forEach(item => {
                           item.checked=this.checkAll
                    });
                }
            },
            watch:{    //监听变量修改
                // 监听list
                list:{
                    handler(newList){
                        this.checkAll=newList.every(item=>item.checked)
                    },
                    deep:true
                }
            }
        })
    </script>
</body>
</html>